#include "forco_os.h"

//初始化系统的滴答时钟
CPU_INT32 OS_SystickInit(CPU_UINT32 ms)
{
    CPU_UINT32 SystickVal = 0;
    SystickVal = ms*SystemCoreClock/1000 - 1;
    if(SystickVal > SysTick_LOAD_RELOAD_Msk)
    {
     return OS_ERR_SYSTICK; 
    }
    //120000000 1ms
	SysTick->LOAD = ms*SystemCoreClock/1000 - 1;
	//设置中断优先级
	NVIC_SetPriority(SysTick_IRQn,(1 << __NVIC_PRIO_BITS) - 1);
	SysTick->VAL = 0; //当前值为0
	//时钟为AHB,减到0触发请求,使能systick定时器
	SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_TICKINT_Msk   | SysTick_CTRL_ENABLE_Msk;
    return OS_ERR_NONE;
}



















